package ${package}.${moduleName}.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import com.cloud.mapper.framework.page.PageResult;
import com.cloud.common.entity.common.CommonResult;
import ${package}.${moduleName}.convert.${ClassName}Convert;
import ${package}.${moduleName}.entity.${ClassName}Entity;
import ${package}.${moduleName}.service.${ClassName}Service;
import ${package}.${moduleName}.dto.${ClassName}Query;
import ${package}.${moduleName}.vo.${ClassName}VO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.stream.Collectors;

/**
* ${tableComment}
*
* @author ${author} ${email}
* @since ${version} ${date}
*/
@RestController
@RequestMapping("${moduleName}/${functionName}")
@Api(tags="${tableComment}")
@AllArgsConstructor
public class ${ClassName}Controller {
    private final ${ClassName}Service ${className}Service;

    @PostMapping("/page")
    @ApiOperation(value = "分页")
    //@PreAuthorize("hasAuthority('${moduleName}:${functionName}:page')")
    public CommonResult<PageResult<${ClassName}VO>> page(@RequestBody @Valid @ApiParam ${ClassName}Query query){
        PageResult<${ClassName}VO> page = ${className}Service.page(query);

        return CommonResult.success(page);
    }

    @PostMapping("/get")
    @ApiOperation(value = "信息")
    //@PreAuthorize("hasAuthority('${moduleName}:${functionName}:info')")
    public CommonResult<${ClassName}VO> get(@RequestBody @ApiParam ${ClassName}VO vo){
        ${ClassName}Entity entity = ${className}Service.getById(vo.getId());

        return CommonResult.success(${ClassName}Convert.INSTANCE.convert(entity));
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存")
    //@PreAuthorize("hasAuthority('${moduleName}:${functionName}:save')")
    public CommonResult<String> save(@RequestBody @ApiParam ${ClassName}VO vo){
        ${className}Service.save(vo);

        return CommonResult.success("ok");
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改")
    //@PreAuthorize("hasAuthority('${moduleName}:${functionName}:update')")
    public CommonResult<String> update(@RequestBody @Valid @ApiParam ${ClassName}VO vo){
        ${className}Service.update(vo);

        return CommonResult.success("ok");
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除")
    //@PreAuthorize("hasAuthority('${moduleName}:${functionName}:delete')")
    public CommonResult<String> delete(@RequestBody @ApiParam List<String> idList){
        ${className}Service.delete(idList.stream().map(item->Long.parseLong(item)).collect(Collectors.toList()));

        return CommonResult.success("ok");
    }
}